#include "../buffer/buffer.h"
#include <string>
#include <unordered_map>
#include <unordered_set>

namespace zh
{
    class HttpRequest
    {
    public:
        enum class ParseState
        {
            REQUEST_LINE,
            REQUEST_HEADER,
            REQUEST_BODY,
            FINISHED
        };

        HttpRequest()  = default;
        ~HttpRequest() = default;

        void initialize();

        bool parse(Buffer& buffer);

        bool isKeepAlive() const;

        std::string getPath() const;
        std::string getMethod() const;

    private:
        bool parseLine(const std::string& line);
        bool parseHeader(const std::string& header);
        bool parseBody(const std::string& body);

        bool parsePath();
        bool parsePost();

        ParseState m_parseState;

        std::string m_method;
        std::string m_path;
        std::string m_version;
        std::string m_body;

        std::unordered_map<std::string, std::string> m_header;
        std::unordered_map<std::string, std::string> m_post;

        static const std::unordered_set<std::string> s_DefaultHTML;
    };
} // namespace zh